﻿using Ionic.Zip;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TestZip
{
    public partial class CompressProcess : Form
    {
        public CompressProcess()
        {
            InitializeComponent();
        }

        public delegate void Up();

        public void Zip_SaveProgress(object sender, SaveProgressEventArgs e)
        {
            this.BeginInvoke(new Up(() =>
            {
                if (e.EventType == ZipProgressEventType.Saving_EntryBytesRead)
                {
                    progressBar1.Minimum = 0;
                    progressBar1.Maximum = (int)e.TotalBytesToTransfer;
                    progressBar1.Value = (int)e.BytesTransferred;
                    progressBar1.Step = (progressBar1.Maximum - progressBar1.Minimum) / 20;
                    return;
                }

                if (e.EventType == ZipProgressEventType.Saving_Completed)
                {
                    this.Close();
                    return;
                }

                progressBar1.Value = (int)e.BytesTransferred;
            }));
        }
    }
}
